﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EcoSystem.Permissions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
using Volo.Abp.Application.Dtos;

namespace EcoSystem;

/// <summary>
/// 系统用户管理
/// </summary>
[Area(EcoSystemRemoteServiceConsts.ModuleName)]
[RemoteService(Name = EcoSystemRemoteServiceConsts.RemoteServiceName)]
[Route("api/Platform/systemUser")]
public class SystemUserController : EcoSystemController, ISystemUserAppService
{
    private readonly ISystemUserAppService _service;

    public SystemUserController(ISystemUserAppService service)
    {
        _service = service;
    }

    /// <summary>
    /// 创建
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<SystemUserDto> CreateAsync(CreateOrUpdateSystemUserDto input)
    {
        return await _service.CreateAsync(input);
    }

    /// <summary>
    /// 获取详情
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet]
    [Route("{id}")]
    public async Task<SystemUserDto> GetAsync(Guid id)
    {
        return await _service.GetAsync(id);
    }

    /// <summary>
    /// 修改
    /// </summary>
    /// <param name="id"></param>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPut]
    [Route("{id}")]
    public async Task<SystemUserDto> UpdateAsync(Guid id, CreateOrUpdateSystemUserDto input)
    {
        return await _service.UpdateAsync(id, input);
    }


    /// <summary>
    /// 列表查询
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<PagedResultDto<SystemUserDto>> GetListAsync(GetSystemUserInput input)
    {
        return await _service.GetListAsync(input);
    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpDelete]
    [Route("{id}")]
    public async Task DeleteAsync(Guid id)
    {
        await _service.DeleteAsync(id);
    }

    /// <summary>
    /// 不分页查询
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    [HttpGet]
    [Route("getall")]
    public async Task<List<SystemUserDto>> GetAllListAsync(GetSystemUserInput input)
    {
        return await _service.GetAllListAsync(input);
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="roleName"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    [HttpGet]
    [Route("{roleName}/users")]
    public async Task<List<SystemUserDto>> GetUsersForRoleAsync(string roleName)
    {
        return await _service.GetUsersForRoleAsync(roleName);
    }

    /// <summary>
    /// 修改密码
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    [HttpPost]
    [Route("changePassword")]
    public async Task ChangePasswordAsync(ChangePasswordInputDto input)
    {
        await _service.ChangePasswordAsync(input);
    }

    /// <summary>
    /// 重置用户密码
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    [HttpPost]
    [Route("resetPassword")]
    public async Task ResetPasswordAsync(ResetPasswordInputDto input)
    {
        await _service.ResetPasswordAsync(input);
    }
}
